<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            height: 2000px;
        }
    </style>
</head>
<body>
    <h1>window.onscroll事件</h1>
    <script>
        //防抖
        // let timer=null
        // window.onscroll=function(){
        //     if(timer!=null){
        //         clearTimeout(timer);
        //     }
        //     timer=setTimeout(() => {
        //     console.log("hello,world");
        //     timer=null
        //     }, 500);
        // }
        //节流
        let mark=true
        window.onscroll=function(){
            if(mark){
                setTimeout(() => {
                    console.log("hello,world")
                    mark=true;
                }, 500);
            }
            mark=false;
        }
    </script>
</body>
</html>